<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;

/**
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
    * @var yiike\store\model\TtycCategorySearch $searchModel
*/

$this->title = Yii::t('models', '分类管理');
$this->params['breadcrumbs'][] = $this->title;

if (isset($actionColumnTemplates)) {
$actionColumnTemplate = implode(' ', $actionColumnTemplates);
    $actionColumnTemplateString = $actionColumnTemplate;
} else {
Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . '添加', ['create'], ['class' => 'btn btn-success']);
    $actionColumnTemplateString = " {update} {delete}";
}
$actionColumnTemplateString = '<div class="action-buttons">'.$actionColumnTemplateString.'</div>';
?>
<div class="box box-info giiant-crud ttyc-category-index">
    <div class="box-header with-border">
        <div class="box-title">
            <?= Yii::t('models', '分类管理') ?>
        </div>
    </div>
    <div class="box-body">
    <?php
//             echo $this->render('_search', ['model' =>$searchModel]);
        ?>

    
    <?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function(){alert("yo")}']]) ?>


    <div class="clearfix crud-navigation">
        <div class="pull-left">
            <?= Html::a('<span class="glyphicon glyphicon-plus"></span> ' . '添加', ['create','parentid'=>0], ['class' => 'btn btn-success']) ?>
        </div>

        <div class="pull-right">
        </div>
    </div>

    <hr />

    <div class="table-responsive">
        <div id="w1" class="grid-view">
            <table class="table table-striped table-bordered table-hover"><thead>
                <tr class="x">
                    <th class="action-column">&nbsp;</th>
                    <th>ID</th>
                    <th>
                        分类名称
                    </th>
                    <th>图标</th>
                    <th>排序</th>
                    <th>是否开启</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach($category as $k=>$v){ ?>
                <tr data-key="10">
                    <td nowrap="nowrap">
                        <div class="action-buttons">
                            <?= Html::a(" <span class='glyphicon glyphicon-pencil'></span>", ['update','id'=>$v['id']]) ?>
                            <?= Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $v['id']], [
                                'data' => [
                                    'confirm' => '您确定要删除吗?',
                                    'method' => 'post',
                                    'title'=>'删除'

                                ],
                            ]) ?>
                        </div>
                    </td>
                    <td><?php echo $v['id']; ?></td>
                    <td><?php echo $v['name']; ?>

                        <?php if($v['parentid']==0){ ?>
                            <?= Html::a( '添加子分类', ['create','parentid'=>$v['id']]) ?>
                        <?php } ?>
                    </td>
                    <td>
                        <?= Html::img(Yii::getAlias('@storageUrl/source').'/'.$v['logo'], ['alt' => 'logo','width'=>100]) ?>
                    </td>
                    <td><?php echo $v['displayorder']; ?></td>
                    <td>
                        <?php if($v['enabled']==1){?><label class="label label-success" for="">启用</label><?php }else{?><label class="label label-warning" for="">关闭</label><?php } ?>
                    </td>

                </tr>
                    <?php if(!empty($v['sub'])){ ?>
                <?php foreach($v['sub'] as $row){?>
                    <tr data-key="10">
                        <td nowrap="nowrap">
                            <div class="action-buttons">

                               <?= Html::a(" <span class='glyphicon glyphicon-pencil'></span>", ['update','id'=>$row['id']]) ?>
                                <?= Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $row['id']], [
                                    'data' => [
                                        'confirm' => '您确定要删除吗?',
                                        'method' => 'post',
                                        'title'=>'删除'

                                    ],
                                ]) ?>
                            </div>
                        </td>
                        <td><?php echo $row['id']; ?></td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['name']; ?></td>
                        <td>
                            <?= Html::img(Yii::getAlias('@storageUrl/source').'/'.$row['logo'], ['alt' => 'logo','width'=>100]) ?>
                        </td>
                        <td><?php echo $row['displayorder'] ?></td>
                        <td><?php if($row['enabled']==1){?><label class="label label-success" for="">启用</label><?php }else{?><label class="label label-warning" for="">关闭</label><?php } ?></td>
                    </tr>
                    <?php } ?>
                        <?php } ?>
                <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
        <?php \yii\widgets\Pjax::end() ?>
    </div>
</div>




